<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>安全巡检模板设置</title>
</head>
<body>
	<div class="content-container" data-options="region:'center'">
		<div class="panel-header">
			<div class="panel-title">安全巡检模板列表</div>
		</div>
		<table id="pro_table" class="easyui-datagrid" style="height: 100%">
		</table>

		<div id="pro_tb">
			<div>
				<a href="javascript:void(0)" class="d-btn btn-blue" onclick="newpro()">添加</a>
				<a href="javascript:void(0)" class="d-btn btn-green" onclick="updatepro()">编辑</a>
				<a href="javascript:void(0)" class="d-btn btn-red" onclick="openpro()">启用/禁用</a>
				<a href="javascript:void(0)" class="d-btn btn-bluegreen" onclick="uppro()">上移</a>
				<a href="javascript:void(0)" class="d-btn btn-bluegreen" onclick="downpro()">下移</a>
			</div>

		</div>
	</div>
	<div id="proDlg" class="easyui-dialog info_dialog" style="width: 500px; padding: 10px 20px" closed="true"
		buttons="#pro-dlg-buttons">
		<div class="title"></div>
		<form id="proFm" method="post">
			<div class="content_container">
				<table class="content_table">
					<tr>
						<td style="width: 100px;">内容：</td>
						<td>
							<input class="easyui-textbox" id="content" name="content" data-options="required:true,multiline:true,"
								style="height: 60px; width: 300px;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">种类：</td>
						<td>
							<select class="easyui-combobox" id="type" data-options="required:true,panelHeight: 'auto'" name="type"
								required="true" style="width: 200px;">
								<option value="0">勾选</option>
								<option value="1">文字</option>
							</select>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div id="pro-dlg-buttons">
		<a href="# " class="easyui-linkbutton ok " onclick="savePro()">保存</a>
		<a href="# " class="easyui-linkbutton btn-cancel " onclick="javascript:$('#proDlg').dialog('close')">取消</a>
	</div>
</body>
<script type="text/javascript">
	var currentPro;
	$(document).ready(function() {
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			url : "inspectionitem",
			method : 'get',
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'content',
				title : '内容',
				width : ''
			},{
				field : 'companyid',
				title : '公司',
				width : '',
				formatter : function(value,row,index) {
					if (row.company){
						return row.company.name;
					}
				}
			},{
				field : 'type',
				title : '种类',
				width : '',
				formatter : function(value,row,index) {
					if (value == 0){
						return value = '勾选';
					}else{
						return value = '文字';
					}
				}
			},{
				field : 'status',
				title : '状态',
				width : '',
				formatter : function(value,row,index) {
					if (value == 2){
						return value = '启用';
					}else{
						return value = '禁用';
					}
				}
			} ] ]
		});
	});
	function refreshProTable() {
		$('#pro_table').datagrid('reload');
	}
	function newpro() {
		$("#proDlg").dialog('open').dialog('setTitle', '添加安全巡检模板');
		$("#proFm").form('clear');
		$("#type").combobox('enable');
		currentPro = {};
	}
	function updatepro() {
		currentPro = $("#pro_table").datagrid('getSelected');
		if (currentPro){
			$("#proDlg").dialog('open').dialog('setTitle', '更新安全巡检模板');
			$("#proFm").form('load', currentPro);
			$("#type").combobox('disable');
		}else{
			$.messager.alert('更新', '请选择要更新的安全巡检模板', 'warning');
		}
	}
	function openpro() {
		currentPro = $("#pro_table").datagrid('getSelected');
		if (currentPro.status == 2){
			currentPro.status = 1;
		}else{
			currentPro.status = 2;
		}
		$.ajax({
			type : 'POST',
			url : "inspectionItemSave.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '保存巡检模板',
						msg : '保存巡检模板成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('保存巡检模板', '保存巡检模板失败', 'error');
				}
				$('#proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	function deletepro() {
		$.ajax({
			type : 'POST',
			url : "inspectionItemDelete.do?inspectionItemid=" + currentPro.id,
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '禁用',
						msg : '禁用成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('禁用', '禁用失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function uppro() {
		$.ajax({
			type : 'POST',
			url : "inspectionItemSort.do?inspectionItemId=" + currentPro.id + "&&operation=1",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '上移',
						msg : '上移成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('上移', '上移失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function downpro() {
		$.ajax({
			type : 'POST',
			url : "inspectionItemSort.do?inspectionItemId=" + currentPro.id + "&&operation=2",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '下移',
						msg : '下移成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('下移', '下移失败', 'error');
				}
			},
			dataType : "json"
		});
	}
	function savePro() {
		if (!$("#proFm").form('validate'))
			return;
		var content = $("#content").textbox('getValue');
		currentPro.content = content;
		var type = $("#type").combobox('getValue');
		currentPro.type = type;
		$.ajax({
			type : 'POST',
			url : "inspectionItemSave.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '保存安全巡检模板',
						msg : '保存安全巡检模板成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('保存安全巡检模板', '保存安全巡检模板失败', 'error');
				}
				$('#proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
</script>
</html>